<template>
	<div>
    <nut-navbar :title="'设置'" ></nut-navbar>
		<nut-cell-group title="个人设置">
			<nut-cell icon="user-o" title="个人信息" :value="user.name" is-link @click="usercenter" />
			<nut-cell icon="lock" title="密码修改" is-link @click="altpwd" />
		</nut-cell-group>
		<nut-cell-group title="系统信息">
			<nut-cell center icon="envelop-o" title="官网地址" value="v5.sanzhiyun.cn" />
			<nut-cell center icon="aim" title="关于我们" />
		</nut-cell-group>
		<nut-cell-group title="系统设置">
			<nut-cell icon="wap-home-o" center title="更新系统" is-link @click="toupdate"  />
			<nut-cell icon="wap-home-o" center title="退出登录" is-link @click="logout"  />
		</nut-cell-group>
	</div>
</template>
<script setup>
import tool from "@/utils/tool";
import {onMounted, reactive, ref} from "vue";
import {useRouter} from "vue-router";

const user = ref({})
const autoLeft = ref(false)
const router = useRouter()
onMounted(() => {
  user.value = tool.data.getUser()
  tool.post('app/getUser', {id: user.value.id}).then(ret => {
    if(ret.stat) {
      user.value = ret.data
      autoLeft.value = ret.data.autoLeft
    }
  })
})

const left = (val) => {
  tool.post('sets/setAutoLeft', {id: user.value.id, autoLeft: val})
}
const scan = () => {

}
const usercenter = () => {
  router.push({name: 'account'})
}
const altpwd = () => {
  router.push({name: 'altpwd'})
}
const logout = () => {
  tool.confirm('是否退出 ？', '操作提示').then( () => {
    tool.data.logout()
    setTimeout(() => {
      router.replace({name: 'login'})
    }, 100)
    //
  })
}
const toupdate = () => {
  tool.suc('更新中....')
  setTimeout(() => {
    window.location.reload()
  }, 500)
}
const clearcache = () => {
  tool.confirm('清除缓存文件并退出 ？', '操作提示').then( () => {
    tool.data.clear()
    tool.data.logout()
    router.replace({name: 'login'})
  })
}


</script>
